
var siteUrl = '/sites/kensite2016';
var clientContext;
var oWebsite;

$(function () {
    SP.SOD.executeFunc('sp.js', 'SP.ClientContext', main);
});

function main (){
    clientContext = new SP.ClientContext(siteUrl);
    oWebsite = clientContext.get_web();
}

function createList() {
    
    
    var listCreationInfo = new SP.ListCreationInformation();
    listCreationInfo.set_title('myNewList');
    listCreationInfo.set_templateType(SP.ListTemplateType.genericList);

    this.oList = oWebsite.get_lists().add(listCreationInfo);

    clientContext.load(oList);

    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}

function onQuerySucceeded() {
    var result = oList.get_title() + ' created.';
    alert(result);
    addFieldToList();
}

function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}

function addFieldToList() {
    var oList = clientContext.get_web().get_lists().getByTitle('myNewList');

    //this.oField = oList.get_fields().addFieldAsXml('<Field DisplayName=\'MyField\' Type=\'Number\' />', true, SP.AddFieldOptions.defaultValue);
    this.oField = oList.get_fields().addFieldAsXml("<Field Type=\'Choice\' DisplayName=\'ha ha\' Required=\'TRUE\' EnforceUniqueValues=\'FALSE\' Indexed=\'FALSE\' Format=\'Dropdown\' FillInChoice=\'FALSE\' StaticName=\'haha\' Name=\'haha\' ColName=\'nvarchar3\' RowOrdinal=\'0\' Version=\'1\'><Default>Enter Choice #1</Default><CHOICES><CHOICE>Enter Choice #1</CHOICE><CHOICE>Enter Choice #2</CHOICE><CHOICE>Enter Choice #3</CHOICE></CHOICES></Field>", 
    true, SP.AddFieldOptions.defaultValue);

    var fieldNumber = clientContext.castTo(oField,SP.FieldChoice);
    //fieldNumber.set_maximumValue(100);
    //fieldNumber.set_minimumValue(35);

    fieldNumber.update();

    clientContext.load(oField);

    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded1), Function.createDelegate(this, this.onQueryFailed1));
}

function onQuerySucceeded1() {
    var result = oField.get_title() + ' added.';
    alert(result);
}

function onQueryFailed1(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}